home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: Ed Howland <102233.3621@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Help - ERROR: Use C++ with iostream.h - ???
- Date: Thu, 11 Apr 1996 01:37:51 -0700
- Organization: CompuServe Incorporated
- Message-ID: <316CC4DF.1E64@compuserve.com>
- References: <31671633.33DD@inforamp.net> <N.040896.100149.11@ix.netcom.com> <milodDpK638.23E@netcom.com> <4kedrk$fv@nw002.infi.net>
- NNTP-Posting-Host: ad49-212.compuserve.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (Win95; I)
-
- This is probably due to a nameing convention difference between his
- computer at school and home. Unix C programs are typically named with a
- ".c" extension. C++ programs use an uppercase ".C" extension. If you
- copy this file to a DOS floppy or download from an FTP site, to a
- DOS/Windows machine, it will be copyied with a ".c" extension (or ".C")
- but since case is irrelevant in DOS, most compilers will treat it as a C
- program. You are right, it must be renamed.
-
- Using ".cpp" for C++ files is usually OK, and avoids recognition
- problems for you later on. Note, there is typically not a requirement
- for header files to be named ".hpp", since these are interpreted as the
- type of the current compilation unit (either .c or .cpp). Most older .h
- files (like stdio.h) are now C++ - safe. So you can be sure that you
- can include both C and CPP headers in your C++ code (although the other
- case is not true.)
-
- Note that you can do this as well. If you have any older headers that
- you want to include in your C++ source, do the following:
-
-
- ---- oldchdr.h ---------
- #ifndef INC_OLDCHDR_H
- #define INC_OLDCHDR_H
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- /* Your old C declaration here
-
-
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
-
-
- This works under Unix and DOS and everywhere else. the define
- "__cplusplus" is guaranteed to be true for C++ compilation units, and
- false otherwise. The 'extern "C" { }' will force anything in the braces
- to emit non-name mangled symbols. Thus the linker will find and link to
- your older C libraries.
-
- So it is perfectly all right to name your headers with just ".h" for the
- extenstion. Note that for new style headers in C++ (such as the
- standard template library) the include statement skips the extension
- altogether:
-
- #include <template>
-
- Read up on the use of namespaces, here.
-
-
- glenn wrote:
- >
- > I used to have the same problem with my school programs. The problem
- > might be in the setup of the program. I don't know what compiler you
- > are using, but you need to specify where your lib files and include
- > files reside in your computer. If you are running a project from the
- > school computer, it could be in a different directory.
- > Glenn
- > milod@netcom.com (John DiCamillo) wrote:
- >
- > >>> When I run a program I brought from schoo, that is properly formatted and
- > >>> runs on the UNIX/PowerPC system there, I get an error like "Use C++ with
- > >>> iostream.h". I even renamed the first character in the header file from
- > >>> an upper case "I" to a lower case "i". Any ideas?
- >
- > >It probably means that your C++ compiler "thinks" its
- > >compiling a C program, not a C++ program. Some compilers
- > >are picky about the filename extensions:
- >
- > > use *.cpp for C++ source files
- > > use *.hpp for C++ header files
- >
- > >Note: I'm not saying that files "should" be named a
- > >certain way, only that some compilers may insist on it.
- >
- > >Also, there is usually a compiler setting to force the
- > >compiler to treat all input files as either C or C++
- > >source code. Try the help system to find the appropriate
- > >incantation.
- >
- > >--
- > > ciao,
- > > milo
- > >================================================================
- > > John DiCamillo Fiery the Angels Fell
- > > milod@netcom.com Deep thunder rode around their shores
-
- --
- Ed Howland | Where's the British Beef?
- Eagle Creek Systems | Billy and Bobby up in a tree...
- Consultant to the Stars! | Line Item Veto-I-N-G
- 102233.3621@compuserve.com | No-No-NAFTA, says Ross P.
-